* Stata do-file, Robustness tests for Chapter 9, Mark R. Beissinger, 
*    The Revolutionary City  
version 17
clear all
set more off
log using Robustnesstestfiles\Logfiles\robustnesstestschapter9.log, replace
* ============================================================================
* ROBUSTNESS CHECKS FOR STATISTICAL RESULTS APPEARING IN CHAPTER 9
* STATA  
* Robustness checks for results reported in Chapter 9 
* Author: Mark R. Beissinger  
* Date:  January 2022  
* Princeton, NJ 
* =============================================================================
* BEFORE RUNNING, YOU MUST SET THE DEFAULT PATH FOR WHERE THE DATA
*   FILES RESIDE
* =============================================================================
* Before running, download the following packages for STATA:
*	collin from https://stats.oarc.ucla.edu/stata/ado/analysis/
*	eststo and esttab from http://www.stata-journal.com/software/sj14-2
* ============================================================================
* The following datafiles are used for this chapter:
*   revolutionaryeps.dta--Cross-sectional dataset of revolutionary episodes
*   matcheddiffindifflong.dta--Panel dataset of successful revolutions and 
*		matched cases for pre-revolutionary and post-revolutionary periods
*   simplediffindifflong.dta--Panel dataset of successful and failed urban 
*		civic and social revolutionary episodes for pre-revolutionary 
*		and post-revolutionary periods
*   fullsamplediffindifflong.dta--Panel dataset of all revolutionary episodes
*		for pre-revolutonary and post-revolutionary periods
* =============================================================================
* The following files are produced by these robustness tests: 
*	--Robustnesstestfiles\Logfiles\robustnesstestschapter9.log
*	--84 graphs of effects
*		The graphs have been attached to the end of the pdf output file
*		  produced for these robustness tests.
* =============================================================================

* ***************************************************************************
* PLEASE READ--IMPORTANT EXPLANATION OF WHAT FOLLOWS
* ***************************************************************************
*
* In Chapter 9 of The Revolutionary City, the diff-and-diff analyses were
* not used as a way of estimating treatment effects. The reasons for this
* are detailed in Appendix 4G (pp. 488-492), which provides a discussion of
* the ways in which revolutions violate the various assumptions of the 
* diff-in-diff model necessary for estimating treatment effects. Instead, 
* the diff-and-diff setup in Chapter 9 was used for purposes of controlled
* comparison--for describing the evolution of the particular variables examined, 
* to identify trends before and after revolution, and to compare these
* between different types of revolutions, between succcessful and failed 
* revolutionary episodes, and between countries experiencing revolutionary 
* contention and matched counterparts that did not. 
*
* Indeed, many of the comparisons presented in Chapter 9 do not involve "treatment" 
* at all, but rather compare patterns of development after different types of 
* revolutions, or patterns of development in societies experiencing successful
* revolutions with those that experienced failed ones.  There was no "treatment" 
* effect that could be estimated in these cases, and the purpose instead was to
* describe the different trajectories of the variables of interest under these 
* constrasting conditions. The closest this chapter comes to potentially 
* identifying a treatment effect for revolution was in its matched case 
* comparisons that compared societies experiencing revolutionary contention with 
* societies that were similar in many respects but did not experience revolutionary 
* contention over the period. There are considerable issues involved
* in such comparisons, though they are about the best that can be done to estimate
* the counterfactual of what might have happened had revolution never occurred.
* However, I did not estimate a "treatment" effect in these cases, preferring
* instead to use the setup to compare rather than identify causaion. The 
* quasi-"treatment" variable (revny) used in these specifications actually included  
* both treatment and pre-treatment years rather than differentiating between 
* "treatment" and pre-"treatment" years, as a normal diff-in-diff setup would do.
* The year prior to revolutionary onset was used as the base for the comparison. 
* The setup also included a unit-time control. 
*
* In these robustness tests, I instead explored the extent to which a "treatment"  
* effect (ATET) could be estimated for all of the matched comparisons conducted 
* in the chapter, as well as the extent to which some of the key statistical   
* assumptions for estimating a treatment effect for revolution held (Please note 
* that, as detailed in The Revolutionary City, there are other statistical
* assumptions necessary for identifying treatment effects that are not tested
* here and that may not hold true for many of the revolutionary episodes in the
* sample). In particular, I explore: 1) if an ATET were estimated for the 
* relationship, would it be statistically significant; 2) whether parallel 
* trends assumptions for the pre-revolutionary period hold; 3) whether
* treatment effects are observed in anticipation of actual treatment (i.e.,
* Granger causation, in the sense that the outcome variable may be causing
* treatment); 4) how stable any treatment effects are over the post-revolutionary 
* period (through the introduction leads and lags); 5) whether the introduction 
* of additional alternative treatment variables for times outside of revolutionary 
* contention (i.e., immediately before and immediaately after revolution) affects 
* the relationship (what some might think of as a kind of statistical placebo 
* test, though this in no way should be considered a true placebo test, which is 
* not possible in events like revolutions); and 6) whether the introduction 
* of autoregressive lags for the dependent variable alters any relationships 
* (given that the trajectory of many of the dependent variables is autoregressive). 
*
* As will be seen, only in a relatively few cases does revolution as a "treatment" 
* fully pass these particular statistical hurdles to causal identification.
* There are particular issues with social revolutions, as the small size of the 
* samples for which data on the dependent variables were available severely challenges 
* identification of "treatment" effects for social revolutions at conventional 
* levels of statistical significance (The number of social revolutions in the 
* sample ranges approximately from a low of 5 to a high of 11. One should 
* therefore be cautious about drawing conclusions concerning the absence of any 
* effect from social revolution in these cases.  The data are just too 
* limited in most cases. Moreover, some causal processes are simply too slow-
* moving to be captured in a statistically significant manner in these tests.
* Thus, infant mortality and under-five child mortality change relatively slowly
* over time; they may be affected by revolution (and there is some evidence that
* they are), but the statistical significance of these effects may not be 
* evident for many years after revolution.  Also, I do not test for the influence 
* of other control variables that might affect relationships, but it should be  
* noted that this kind of specification error is likely widespread in the tests  
* presented below. 
*
* For these tests, I use the xtdidregress command and post-estimation tests 
* that were newly available in Stata 17. These greatly simplify the processs of
* of post-estimation tests. But for that reason, in contrast to all other do-files, 
* this do-file requires Stata 17 to run the tests properly.
*
* In these robustness tests I also present graphs of average trends for all  
* variables discussed in Chapter 9 that were not presented visually. The  
* regression results themselves can be found in the Stata do-file for the chapter. 
* Confidence intervals are not provided in these graphs to enhance the 
* visibility of trends. All graphs produced were labeled and attached to the end  
* of the pdf robustness test output files available for the chapter.
*
* ****************************************************************************
	

* ***************************************************************************
* INITIALIZING PROGRAMS USED IN THE ROBUSTNESS TESTS
* 	Programs initialized are called in the analyses below
* ***************************************************************************

quietly{
* ++++++++++++++++++++++++++++++++++++++++++++++++
* INITIATE PROGRAMS USED FOR MULTIPLE IMPUTATION
* +++++++++++++++++++++++++++++++++++++++++++++++

* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Simple comparisons of social vs. urban civic--chp9simpmultimp
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

capture program drop chp9simpmultimp
program chp9simpmultimp
* Multiple imputation 
* Establish sample
keep year location cowcode revid nameofrevolution success leftist urbancivic incgovcommunist $yvar
mi set mlong
* Drop cases that lack pre-treatment information
mi reshape wide $yvar, i(revid) j(year)
local j = 0
local k = 1
local l = 2
drop if $yvar`j'==. & $yvar`k'==. & $yvar`l'==.
mi reshape long $yvar, i(revid) j(year)
* Obtain number of imputations
misstable summarize $yvar, gen(miss)
tab miss$yvar  if (urbancivic==1 | leftist==1), matcell(x)
scalar fir = x[1,1]
scalar sec = x[2,1]
global mnum = 10 * ceil((100 * (sec/(fir + sec)))/10)
display $mnum
drop miss$yvar
* Engage in imp/utation
mi reshape wide $yvar, i(revid) j(year)
* Make lists of variables that do and do not need imputation
forvalues i = 0(1)10 {
* timei yvar
scalar alist`i'=" "
scalar blist`i'=" "
count if $yvar`i'==.
if r(N)>0 {
 scalar alist`i' = "$yvar`i'"
}
if r(N)==0 {
 scalar blist`i' = "$yvar`i'"
}
display alist`i'
display blist`i'
}
* Final computation
local alist alist0 + " " + alist1 + " " + alist2 + " " + alist3 + " " + alist4 + " " + alist5  + " " + alist6  + " " + alist7  + " " + alist8  + " " + alist9  + " " + alist10
local blist blist0 + " " + blist1 + " " + blist2 + " " + blist3 + " " + blist4 + " " + blist5  + " " + blist6  + " " + blist7  + " " + blist8  + " " + blist9  + " " + blist10
display `alist'
display `blist'
scalar afull = `alist'
global afulllist = afull
scalar bfull = `blist'
global bfulllist = bfull
* Register variables to be imputed
mi register imputed $afulllist
misstable summarize $afulllist, gen(miss)
mi xtset, clear
* Impute
mi impute chained (regress) $afulllist = success leftist $bfulllist, add($mnum) rseed (1234) chaindots 
* Engage in analysis
mi reshape long $yvar, i(revid) j(year)
mi xtset revid year
end

* +++++++++++++++++++++++++++++++++++++++++
* Full sample comparisons--chp9fullmultimp
* +++++++++++++++++++++++++++++++++++++++++
capture program drop chp9fullmultimp
program chp9fullmultimp
* Multiple imputation 
* Establish sample
keep year cowcode revid nameofrevolution success leftist urbancivic $yvar
mi set mlong
* Drop cases that lack pre-treatment information
mi reshape wide $yvar, i(revid) j(year)
local j = 0
local k = 1
local l = 2
drop if $yvar`j'==. & $yvar`k'==. & $yvar`l'==.
mi reshape long $yvar, i(revid) j(year)
* Obtain number of imputations
misstable summarize $yvar, gen(miss)
tab miss$yvar, matcell(x)
scalar fir = x[1,1]
scalar sec = x[2,1]
global mnum = 10 * ceil((100 * (sec/(fir + sec)))/10)
display $mnum
drop miss$yvar
* Engage in imputation
mi reshape wide $yvar, i(revid) j(year)
* Make lists of variables that do and do not need imputation
forvalues i = 0(1)10 {
* timei yvar
scalar alist`i'=" "
scalar blist`i'=" "
count if $yvar`i'==.
if r(N)>0 {
 scalar alist`i' = "$yvar`i'"
}
if r(N)==0 {
 scalar blist`i' = "$yvar`i'"
}
display alist`i'
display blist`i'
}
* Final computation
local alist alist0 + " " + alist1 + " " + alist2 + " " + alist3 + " " + alist4 + " " + alist5  + " " + alist6  + " " + alist7  + " " + alist8  + " " + alist9  + " " + alist10
local blist blist0 + " " + blist1 + " " + blist2 + " " + blist3 + " " + blist4 + " " + blist5  + " " + blist6  + " " + blist7  + " " + blist8  + " " + blist9  + " " + blist10
display `alist'
display `blist'
scalar afull = `alist'
global afulllist = afull
scalar bfull = `blist'
global bfulllist = bfull
* Register variables to be imputed
mi register imputed $afulllist
misstable summarize $afulllist, gen(miss)
mi xtset, clear
* Impute
mi impute chained (regress) $afulllist = success $bfulllist, add($mnum) rseed (1234) chaindots 
* Engage in analysis
mi reshape long $yvar, i(revid) j(year)
mi xtset revid year
end

* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Matched sample comparisons--chp9fullmultimp--chp9matchmultimp
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Program chp9matchmultimp
capture program drop chp9matchmultimp
program chp9matchmultimp
* MULTIPLE IMPUTATION 
* ESTABLISH SAMPLE
keep diffid year country cowcode _prime_id revny revid nameofrevolution revcowcode success startyear freqwt leftist urbancivic $yvar
mi set mlong
* DROP CASES THAT LACK PRE-TREATMENT INFORMATION
mi reshape wide $yvar, i(diffid) j(year)
local j = 0
local k = 1
local l = 2
* Create new marker for those with no pre-treatment values
generate dropmark1=0
replace dropmark1=1 if $yvar`j'==. & $yvar`k'==. & $yvar`l'==.
* Generate var for number of cases within each revid
generate casenum = 1/freqwt
* Create new marker for revs with matched cases marked for dropping
sort revid diffid
by revid:  generate dropmark2 =  (sum(dropmark1))/casenum
* Drop matched cases if no pre-treatment values
drop if revny==0 & dropmark1==1
* Drop revs with no matched cases left
by revid: egen newcount=count(diffid)
drop if newcount==1
* Drop revs and matched cases in which rev itself has no pre-treatment values
by revid:  generate dropmark3 = sum(dropmark2)
drop if dropmark3>=1
* Create new weight variable
replace newcount = newcount - 1
replace freqwt = 1/newcount
replace freqwt=1 if revny==1
drop dropmark1 dropmark2 dropmark3 casenum newcount
mi reshape long $yvar, i(diffid) j(year)
* OBTAIN NUMBER OF IMPUTATIONS
misstable summarize $yvar, gen(miss)
tab miss$yvar  if success==1 & (urbancivic==1 | leftist==1), matcell(x)
scalar fir = x[1,1]
scalar sec = x[2,1]
global mnum = 10 * ceil((100 * (sec/(fir + sec)))/10)
display $mnum
drop miss$yvar
* ENGAGE IN IMPUTATION
mi reshape wide $yvar, i(diffid) j(year)
* Make lists of variables that do and do not need imputation
forvalues i = 0(1)10 {
* timei yvar
scalar alist`i'=" "
scalar blist`i'=" "
count if $yvar`i'==.
if r(N)>0 {
 scalar alist`i' = "$yvar`i'"
}
if r(N)==0 {
 scalar blist`i' = "$yvar`i'"
}
display alist`i'
display blist`i'
}
* Final computation
local alist alist0 + " " + alist1 + " " + alist2 + " " + alist3 + " " + alist4 + " " + alist5  + " " + alist6  + " " + alist7  + " " + alist8  + " " + alist9  + " " + alist10
local blist blist0 + " " + blist1 + " " + blist2 + " " + blist3 + " " + blist4 + " " + blist5  + " " + blist6  + " " + blist7  + " " + blist8  + " " + blist9  + " " + blist10
display `alist'
display `blist'
scalar afull = `alist'
global afulllist = afull
scalar bfull = `blist'
global bfulllist = bfull
* Register variables to be imputed
mi register imputed $afulllist
misstable summarize $afulllist, gen(miss)
mi xtset, clear
* Impute
mi impute chained (regress) $afulllist = revny $bfulllist, add($mnum) rseed (1234) chaindots 
* RESHAPE TO ENGAGE IN ANALYSIS
mi reshape long $yvar, i(diffid) j(year)
mi xtset diffid year
end


* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* INITIATE PROGRAMS USED IN TESTING TREATMENT EFFECTS IN THE
*   MATCHED DIFF-AND-DIFF ANALYSES
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Test for possible alternative treatment effects
* 	This test creates an alternative treatment variable and substitutes
*	it for the regular treatment variable in the specification (which
*	instead is used a control variable). If the alternative treatment is
*	statistically significant and turns the regular treatment variable
*	insignificant or reduces its effect, then other events occurring at
*	these alternative times could account for outcomes. Four tests are
*	carried out, with alternative treatments tested for t-2, t-1, t+1,
*	and t+2 (i.e., two years on either side of revolutionary contention)
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
capture program drop chp9matchalttreat
program chp9matchalttreat
quietly: eststo clear
* Estimating treatment and alttreatment effects
* Setting up comparison w. no alternative treatment
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
* Setting test #1
quietly: mi passive: generate alttreat=0
quietly: mi passive: replace alttreat=1 if $condvar & revny==1 & year>0
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar treat) (alttreat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
quietly: drop alttreat
quietly: mi update
* Setting test #2
quietly: mi passive: generate alttreat=0
quietly: mi passive: replace alttreat=1 if $condvar & revny==1 & year>1
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar treat) (alttreat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
quietly: drop alttreat
quietly: mi update
* Setting test #3
quietly: mi passive: generate alttreat=0
quietly: mi passive: replace alttreat=1 if $condvar & revny==1 & year>3
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar treat) (alttreat) if  $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
quietly: drop alttreat
quietly: mi update
* Setting test #4
quietly: mi passive: generate alttreat=0
quietly: mi passive: replace alttreat=1 if $condvar & revny==1 & year>4
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar treat) (alttreat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
quietly: drop alttreat
quietly: mi update

end

* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Granger test program for matched diff-and-diff
*	Tests whether treatment effects are observed in anticipation of actual treatment
*	(i.e., whether outcomes may be causing treatment)
*   F-scores are averaged across imputations, and then a p-value is produced
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
capture program drop chp9matchgranger
program chp9matchgranger
mi query
local M = r(M)
scalar finalfscore = 0
scalar finalpvalue = 0
foreach n of numlist 1/`M' {
    mi xeq `n': xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid); estat granger
 scalar fscorep = r(F)
  scalar df_r = r(df_r)
  scalar df = r(df)
  scalar finalfscore = finalfscore + fscorep
  }
scalar finalfscore = finalfscore/`M'
scalar finalpvalue = 1 - F(df, df_r, finalfscore)
 end

* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Grangerplot of leads and lags
* 	Calculates time-specific treatment effects using leads and lags to 
*		assess whether there are any changes in the treatment effect over the 
*		post-treatment time period
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
capture program drop chp9matchgrangerplot
program chp9matchgrangerplot
mi query
local M = r(M)
local list1 lead3 lead2 lead1 lag0 lag1 lag2 lag3 lag4 lag5 lag6 lag7
foreach x in `list1' {
	scalar fin`x' = 0
	scalar finse`x' = 0
	scalar finll`x' = 0
	scalar finul`x' = 0
}
foreach n of numlist 1/`M' {
  mi xeq `n': xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid); estat grangerplot, verbose nodraw post
  matrix A = r(table)
  scalar lead3 = A[1,12]
  scalar lead2 = A[1,13]
  scalar lead1 = 0
  scalar lag0 =  A[1,14]
  scalar lag1 =  A[1,15]
  scalar lag2 =  A[1,16]
  scalar lag3 =  A[1,17]
  scalar lag4 =  A[1,18]
  scalar lag5 =  A[1,19]
  scalar lag6 =  A[1,20]
  scalar lag7 =  A[1,21]
  scalar selead3 = A[2,12]
  scalar selead2 = A[2,13]
  scalar selead1 = 0
  scalar selag0 =  A[2,14]
  scalar selag1 =  A[2,15]
  scalar selag2 =  A[2,16]
  scalar selag3 =  A[2,17]
  scalar selag4 =  A[2,18]
  scalar selag5 =  A[2,19]
  scalar selag6 =  A[2,20]
  scalar selag7 =  A[2,21]

  foreach x in `list1' {
	scalar fin`x' = fin`x' + `x'
	scalar finse`x' = finse`x' + se`x'
}
  }

foreach x in `list1' {
	scalar fin`x' = fin`x'/`M'
	scalar finse`x' = finse`x'/`M'
	scalar finll`x' = fin`x' - (1.96 * (finse`x'))
	scalar finul`x' = fin`x' + (1.96 * (finse`x'))
}
  
* store in a matrix and plot
matrix B = (finlead3,finlead2,finlead1,finlag0,finlag1,finlag2,finlag3,finlag4,finlag5,finlag6,finlag7\finlllead3,finlllead2,finlllead1,finlllag0,finlllag1,finlllag2,finlllag3,finlllag4,finlllag5,finlllag6,finlllag7\finullead3,finullead2,finullead1,finullag0,finullag1,finullag2,finullag3,finullag4,finullag5,finullag6,finullag7)
matrix colnames B = lead3 lead2 lead1 lag0 lag1 lag2 lag3 lag4 lag5 lag6 lag7 
matrix rownames B = beta ll95 ul95

 end

* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Lagged dv test
*   Tests for the effect of lagged values of dv on statistical findings
*	Up to 2 lags of the dv included in the specification to test whether serial
*	  autocorrelation might be responsible all or part of the statistical findings
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
capture program drop chp9matchdvlag
program chp9matchdvlag
quietly: eststo clear
quietly{
* Creating lags
mi passive: generate laggeddv1 = $yvar[_n-1]
mi passive: generate laggeddv2 = $yvar[_n-2]
mi update 
}
* Lags included as control variables
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid)
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar laggeddv1) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid)
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar laggeddv2) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid)
quietly: eststo: mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar laggeddv1 laggeddv2) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid)
quietly: drop laggeddv1 laggeddv2 
quietly: mi update 

end
 
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Program for statistical test for parallel trends (ptrends), matched diff-and-diff 
*   Tests whether linear trends in the outcome variable are parallel between 
* 		control and treatment groups during the pretreatment period
*   F-scores are averaged across imputations, and a p-value produced
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
capture program drop chp9matchptrends
program chp9matchptrends
mi query
local M = r(M)
scalar finalfscore = 0
scalar finalpvalue = 0
foreach n of numlist 1/`M' {
  mi xeq `n': xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid); estat ptrends
  scalar fscorep = r(F)
  scalar df_r = r(df_r)
  scalar df = r(df)
    scalar finalfscore = finalfscore + fscorep
  }
scalar finalfscore = finalfscore/`M'
scalar finalpvalue = 1 - F(df, df_r, finalfscore)
end


}



* ****************************
* INITATING ROBUSTNESS TESTS
* ****************************

* +++++++++++++++++++++++++++++++++++
* POST-REVOLUTIONARY REGIME SURVIVAL
* +++++++++++++++++++++++++++++++++++
clear
use revolutionaryeps.dta, clear
* Set survival data
* Establish data as survival data with reglastyr variable--previously carried out
quietly: stset reglastyr, failure(died==1) origin (time endyear)
* Bootstrap tests
bootstrap, reps(1000) seed(1234) nodots: stcox  leftist  vanguard  civilwar lndeaths lnmonths  c.vdcsrepressavg1to5##c.vdcsrepressavg1to5 if ongoing==0 & success==1
bootstrap, reps(1000) seed(1234) nodots: stcox  leftist  vanguard  civilwar lndeaths lnmonths  vdcsrepressavg1to5 if ongoing==0 & success==1
* 	RESULT: lnmonthsdur remains negative and significant at .05 level or better; 
*			vdcsrepressavg1to5 is positive and significant at .05 level or better only in univariate form
* Multicollinearity test
collin leftist vanguard civilwar lndeaths lnmonths vdcsrepressavg1to5
* All tolerance values above .20, indicating that while multicollinearity is substantial,
* 	it is likely not debilitating

* ===================================================================
* STATE CAPACITY AFTER SUCCESSFUL SOCIAL AND URBAN CIVIC REVOLUTIONS
* ===================================================================

* +++++++++++++++++++++++++++++++++++++
* V-DEM MEASURE OF TERRITORIAL CONTROL
* +++++++++++++++++++++++++++++++++++++
//  SUCCESSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
* Regression results were presented in Chapter 9 do-file
* Graph of results produced here
use simplediffindifflong.dta, clear
global yvar = "vdsvstterr"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
global condvar = "leftist==1"
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("% territory controlled") ylabel(80(5)100 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #1" , span) title("`titvar1'" "Avg marginal predictions for successful episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph1.pdf, replace

* +++++++++++++++++++++++++++++++++++++++++++++++
* MILITARY EXPENDITURE IN THE WAKE OF REVOLUTION
* +++++++++++++++++++++++++++++++++++++++++++++++
//  SUCCESSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
* Regression results were presented in Chapter 9 do-file
* Graph of results produced here
use simplediffindifflong.dta, clear
global yvar = "milex"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
global condvar = "leftist==1"
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("$ mil expenditure") ylabel(1250000(250000)2750000 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #2" , span) title("`titvar1'" "Avg marginal predictions for successful episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph2.pdf, replace

* +++++++++++++++++++++++++++++++
* STATE CAPACITY (HANSON/SIGMAN) 
* +++++++++++++++++++++++++++++++
* Note that sample size is reduced due to temporal coverage of the data

// SUCCESSFUL SOCIAL VS. MATCHED CASES
* Regression results were presented in Chapter 9 do-file
* Will provide graph, test for treatment effect, and check treatment effect estimation assumptions
use matcheddiffindifflong.dta, clear
global yvar = "statecapacity"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "leftist==1 & success==1"
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if $condvar [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ylabel(-1(.25).5 ,format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #3" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph3.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* 	Treatment in this case consists of experiencing a successful social rev vs. no rev in matched cases
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative, but no statistically significant effect (likely sample too small; visual evidence of possible effect)
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically insignificant: no evidence of parallel trends assumption violation
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically insignificant: no evidence that treatment effects were observed prior to treatment period.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(centered) alignment(bottom)) ciopts(recast(rcap)) note("Graph #4" , span) title("`titvar1'""Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph4.pdf, replace
	* RESULT:  The negative impact of revolution on state capacity is short-term, and dissipates relatively quickly.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of any statistically significant effects.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence of AR1 process, but no influence on the treatment variable

	
// SUCCESSFUL URBAN CIVIC VS. MATCHED CASES
* Regression results were presented in Chapter 9 do-file
* Will provide graph, test for treatment effect, and check treatment effect estimation assumptions
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "urbancivic==1 & success==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if $condvar [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ylabel(-.5(.25).5 ,format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful urban civic" )) note("Graph #5" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph5.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment in this case consists of experiencing a successful urban civic rev vs. no rev in matched cases
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative, but not statistically significant
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically insignificant: no evidence that treatment effects were observed prior to treatment period. 
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(centered) alignment(bottom)) ciopts(recast(rcap)) note("Graph #6" , span) title("`titvar1'""Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph6.pdf, replace
	* RESULT:  The negative impact of revolution on state capacity is short-term, and dissipates relatively quickly.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of any statistically significant effects.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
* Control for possible effect of lagged values of the dependent variable on treatment effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence of AR1 process, but no influence on the treatment variable

	
* =================================
* ECONOMIC GROWTH--MATCHED SAMPLES
* =================================
* Regression results were presented in Chapter 9 do-file, and graphs provided
*	in Figures 9.4-9.6
* Will test for treatment effects, and check treatment effect estimation assumptions

// FAILED REVOLUTIONS VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "gdpa1990index"
label var gdpa1990index "Indexed GDPpc (100=yr<onset)"
global notetext "FAILED VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==0"
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a failed rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Marginally statistically significant at the .10 level
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally statistically significant evidence (at the .10 level) that the effects were observed prior to treatment.
	*	Treatment is likely related to economic development.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(centered) alignment(bottom)) ciopts(recast(rcap)) note("Graph #7" , span) title("`titvar1'""Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph7.pdf, replace
	* RESULT:  Effect substantial at first but mitigated over time
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of any diminution of statistical significance in the treatment variable.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
* Control for possible effect of lagged values of the dependent variable on treatment effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT:  Evidence of AR1 and AR2 processes that diminish the statistical significance of treatment.


// SUCCESSFUL REVOLUTIONS VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1"
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Statistically significant at the .001 level--on average, an 11.7% decline
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally statistically significant evidence, at the .10 level, of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally statistically significant evidence (at the .10 level) that the effects were observed prior to treatment.
	*	Treatment is likely related to economic development.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(centered) alignment(bottom)) ciopts(recast(rcap)) note("Graph #8" , span) title("`titvar1'""Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph8.pdf, replace
	* RESULT:  Statistically significant evidence that the effects of "treatment" grow more substantial over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Statistically significant evidence of a decline in t-1, but this does not undermine the statistical significance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: AR1 and AR2 processes that influence the outcome, but do not undermine the statistical significance of treatment.

	
// FAILED SOCIAL VS. MATCHED COUNTERPARTS 
global notetext "FAILED SOCIAL VS. MATCHED CASES"
quietly {
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==0 & leftist==1"
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a failed social rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Statistically significant at the .05 level, with an avg decline of 11.1% as a result of "treatment"
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #9" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph9.pdf, replace
	* RESULT:  Statistically significant evidence that the effects of "treatment" lasts at least 4 yrs, 
	*    and then begins to mitigate.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatments affecting the relationship.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: AR1 and AR2 processes appear to undermine the statistical significance of treatment.

	
// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS 
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & leftist==1"
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Not statistically significant (due to small sample size), but quite substantial decline of 18.5% as a result of treatment
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically significant evidence (at the .05 level) of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #10" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph10.pdf, replace
	* RESULT:  Effect is statistically significant for the first 3 yrs after rev, and then begins to mitigate.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatments affecting the relationship in a substantial way.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: AR1 and AR2 processes, but do not alter the relationship.


// FAILED URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "FAILED URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==0 & urbancivic==1"
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a failed urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive, but not statistically significant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #11" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph11.pdf, replace
	* RESULT:  Not statistically significant, but sign seems to reverse after 1 year.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatments being statistically significant or affecting the relationship in a substantial way.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes, but do not alter the treatment variable substantially.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS 
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & urbancivic==1"
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a failed urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative, but not statistically significant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #12" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph12.pdf, replace
	* RESULT:  Not statistically significant, but the negative effect grows more substantial over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatments being statistically significant or affecting the relationship in a substantial way.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes, but do not alter the treatment variable substantially.



*=======================================================================
* RELATIONSHIP BETWEEN HENISZ MEASURE OF POLITICAL CONSTRAINTS AND 
*    POST-REVOLUTIONARY SOCIAL REVOLUTIONARY AND URBAN CIVIC GOVERNANCE
*=======================================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs and check causal effect assumptions

// SUCCESSSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
quietly: use simplediffindifflong.dta, clear
quietly: global yvar = "polconiii"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Pol constraints measure") ylabel(-.1(.1).7 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #13" , span) title("`titvar1'" "Avg marginal predictions for successful episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph13.pdf, replace

// SUCCESSFUL SOCIAL VS. FAILED SOCIAL
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year if leftist==1, fe vce(robust)
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Pol constraints measure") ylabel(-.1(.1).7 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed" 2 "Successful" )) note("Graph #14" , span) title("`titvar1'" "Avg marginal predictions for social revolutionary episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph14.pdf, replace

// SUCCESSFUL URBAN CIVIC VS. FAILED URBAN CIVIC
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year if urbancivic==1, fe vce(robust)
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Pol constraints measure") ylabel(-.1(.1).7 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed" 2 "Successful" )) note("Graph #15" , span) title("`titvar1'" "Avg marginal predictions for urban civic episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph15.pdf, replace


// SUCCESSFUL SOCIAL VS. MATCHED CASES 
use matcheddiffindifflong.dta, clear
global yvar = "polconiii"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & leftist==1"
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if success==1 & leftist==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Pol constraints measure") ylabel(-.1(.1).7 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched cases" 2 "Succ social" )) note("Graph #16" , span) title("`titvar1'" "Avg marginal predictions, successful social vs. matched cases") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph16.pdf, replace
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a failed urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Not statistically significant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #17" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph17.pdf, replace
	* RESULT:  Not statistically significant, but the signs shift over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatments being statistically significant or affecting the relationship in a substantial way.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes, but do not alter the treatment variable substantially.

	
// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS 
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if success==1 & urbancivic==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Pol constraints measure") ylabel(-.1(.1).7 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched cases" 2 "Succ urban civic" )) note("Graph #18" , span) title("`titvar1'" "Avg marginal predictions, succ urban civic vs. matched cases") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph18.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a failed urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .05 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #19" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph19.pdf, replace
	* RESULT:  Effect remains relatively stable and statistically significant over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Post-revolutionary developments in the first two years after revolution appear to play a critical role, turning the treatment effect
	*				statistically insignificant.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes are present, but do not alter the statistical significance of the treatment variable.


*=============================
* CORRUPTION AFTER REVOLUTION
*=============================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.7
* For matched sample, will test for  treatment effect, and check treatment effect 
*   estimation assumptions


// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdcorr"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & leftist==1"
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but not statistically significant (likely due to small number of social revolutions).
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #20" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph20.pdf, replace
	* RESULT:  Effect remains relatively stable (though statistically insignificant) over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence for alternative treatment effects at different times outside revolutionary contention.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence that AR1  processes are present, and these turn the treatment effect statistically significant at the .10 level
	* 	when included in the specification.

* SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & urbancivic==1"
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative and statistically significant at the .05 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #21" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph21.pdf, replace
	* RESULT:  After an initial decline, effect grows statistically insignicant over time, as corruption
	*    gradually re-emerges.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatment times, and no change to the statistical significance
	*	of the treatment effect. 
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1  processes that do not alter the statistical significance of the treatment variable.


*===============================================
* IMPACT OF REVOLUTION ON INVESTMENT AS % OF GDP
*===============================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for  treatment effects, and check treatment effect 
*   estimation assumptions

// SUCCESSSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
quietly: use simplediffindifflong.dta, clear
global yvar = "investtogdp"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Investment as % of GDP") ylabel(10(5)30 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #22" , span) title("`titvar1'" "Avg marginal predictions for successful episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph22.pdf, replace

* SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "investtogdp"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & leftist==1"
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but not statistically significant (likely due to small number of social revolutions in sample).
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #23" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph23.pdf, replace
	* RESULT:  Effect achieves statistically significance in 4 out of 8 lag years.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence for alternative treatment effects at different times outside revolutionary contention.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence that AR1  processes are present, but these do not affect the statistical
	*	significance of treatment.

	
// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global yvar = "investtogdp"
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but not statistically significant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #24" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph24.pdf, replace
	* RESULT:  No statistically significant lags or leads, but negative impact appears frontloaded 
	*	to the immediate post-revolutionary period.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Treatment effect turns statistically significant when controlled for additional
	*	post-revolutionary treatments--not clear what this indicates.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR@ processes that do not alter the lack of statistical significance of 
	* 	the treatment variable.

	
*=================================================================
* EFFECT OF SOCIAL AND URBAN CIVIC REVOLUTIONS ON PROPERTY RIGHTS 
*=================================================================
* REGRESSION RESULTS WERE PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for  treatment effects, and check treatment effect 
*   estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdproprts"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
* Marginsplot for visualizing trends
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM property rights index") ylabel(.3(.05).6 ,format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #25" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph25.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but not statistically significant (likely due to small number of social revolutions in sample).
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #26" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph26.pdf, replace
	* RESULT:  Consistently negative and statistically insignificant, but grows increasingly negative
	*	over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence for alternative treatment effects at different times outside revolutionary contention.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence that AR1  processes are present, but these do not affect the statistical
	*	significance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM property rights index") ylabel(.5(.1).8 ,format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #27" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph27.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but not statistically significant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Evidence of statistically significant violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #28" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph28.pdf, replace
	* RESULT:  Statistically significant immediately after rev, but then turns insignificant. 
	*	Consistently positive.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Unclear significance of statistically significant result for Alt, t+2.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1  and AR2 processes that do not alter the lack of statistical significance of the treatment variable.
	

*==================================
* EFFECT OF REVOLUTION ON INFLATION
*==================================
* REGRESSION RESULTS WERE PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for treatment effects, and check treatment effect 
*   estimation assumptions

// IMPACT OF REVOLUTIONARY SUCCESSS/FAILURE ON INFLATION
use fullsamplediffindifflong.dta, clear  
quietly: generate anninflatwi = anninflat2   // Must alter variable name due to reshaping of data during multiple imputation
global yvar = "anninflatwi"
quietly: label var anninflatwi "Annual inflation (windsorized)"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9fullmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year, fe
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Percent inflation") ylabel(0(10)40 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed" 2 "Successful" )) note("Graph #29" , span) title("`titvar1'" "Avg marginal predictions, all revs") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph29.pdf, replace

// SUCCESSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
use simplediffindifflong.dta, clear
generate anninflatwi = anninflat2 
global yvar = "anninflatwi"
quietly: label var anninflatwi "Annual inflation (windsorized)"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, re
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Percent inflation") ylabel(0(10)80 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #30" , span) title("`titvar1'" "Avg marginal predictions for successful revs") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph30.pdf, replace

// FAILED SOCIAL VS. FAILED URBAN CIVIC
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==0, re
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Percent inflation") ylabel(0(10)40 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #31" , span) title("`titvar1'" "Avg marginal predictions for failed revs") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph31.pdf, replace

// SUCCESSFUL URBAN CIVIC WITH MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
generate anninflatwi = anninflat2 
global yvar = "anninflatwi"
label var anninflatwi "Annual inflation (windsorized)"
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & urbancivic==1"
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace): xtreg $yvar i.revny##ib(2).year if success==1 & urbancivic==1 [pweight=freqwt], cluster(revid) fe
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Percent inflation") ylabel(0(10)50 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #32" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph32.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but not statistically significant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence for a violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #33" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph33.pdf, replace
	* RESULT:  Consistently positive and statistically insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatments at play.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1  and AR2 processes that do not alter the lack of statistical significance of the treatment variable.
	
*=========================================
* EFFECT OF REVOLUTION ON GOVERNMENT DEBT
*=========================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs

// IMPACT OF REVOLUTIONARY SUCCESSS/FAILURE ON GOVERNMENT DEBT
clear
use fullsamplediffindifflong.dta, clear
global yvar = "debttogdp"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9fullmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year, fe
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Debt to GDP, percent") ylabel(40(10)70 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed" 2 "Successful" )) note("Graph #34" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph34.pdf, replace

// SUCCESSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
use simplediffindifflong.dta, clear
global yvar = "debttogdp"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Debt to GDP, percent") ylabel(40(10)100 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #35" , span) title("`titvar1'" "Avg marginal predictions for successful revs") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph35.pdf, replace

// FAILED SOCIAL VS. FAILED URBAN CIVIC
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==0, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Debt to GDP, percent") ylabel(30(5)50 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #36" , span) title("`titvar1'" "Avg marginal predictions for failed revs") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph36.pdf, replace


*===========================================================
* EFFECT OF REVOLUTION ON V-DEM EQUALITY OF RESOURCES INDEX
*===========================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.8
* Will test for  treatment effects, and check treatment effect estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
 use matcheddiffindifflong.dta, clear
global yvar = "vdeqdr"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & leftist==1"
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and marginally significant at the .10 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #37" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph37.pdf, replace
	* RESULT:  Lags are consistently positive and statistically insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatment at t+1 turns treatment insignificant--points to critical processes after revolutionary contention.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical	significance of treatment.

// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
local titvar1 = titvar
}
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .05 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #38" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph38.pdf, replace
	* RESULT:  Lags are consistently positive, relatively stable, and statistically significant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alt treatment at t+1 turns treatment marginally significant; points to critical 
	*	processes occurring the year after revolution.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not alter the statistical significance of the treatment variable.


*=========================================
* EFFECT OF REVOLUTION ON HEALTH EQUALITY
*=========================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for treatment effects, and check treatment effect 
*   estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdhealtheq"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM health equality index") ylabel(-1.4(.2)0 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #39" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph39.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and marginally significant at the .10 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically significant evidence (at the .10 level) of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #40" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph40.pdf, replace
	* RESULT:  Lags are consistently positive and statistically significant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatment at t+1 turns treatment insignificant--points to critical processes after revolutionary contention.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and (possibly) AR2 processes that turn treatment even more statistically significant.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM health equality index") ylabel(-.3(.1).3 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #41" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph41.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and marginally significant at the .10 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence for a violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #42" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph42.pdf, replace
	* RESULT:  Consistently positive, statistically significant from lags 1-5, effect eventually grows insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alt treatment at t+1 statistically significant and turns treatment insignificant. Points to
	*	critical processes in the wake of revolution.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1  and AR2 processes that turn treatment even more statistically significant.


*==============================================
* EFFECT OF REVOLUTION ON EDUCATIONAL EQUALITY
*==============================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for treatment effects, and check treatment effect 
*   estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdeduceq"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM educational equality index") ylabel(-2(.2)0 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #43" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph43.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #44" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph44.pdf, replace
	* RESULT:  Lags are consistently positive but statistically insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical insignificance of treatment.

	
// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM educational equality index") ylabel(-.3(.1).3 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #45" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph45.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally significant evidence (at the .10 level) for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #46" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph46.pdf, replace
	* RESULT:  Consistently positive; leads 1 and 2 and lags 1-3 statistically significant, but effect becomes 
	*	insignificant over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Evidence for potential pre-revolutionary "treatments" that turn treatment marginally significant.
	*	May be due to violation of parallel trends assumption.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes that do not affect the statistical insignificance of treatment.


*==========================================
* EFFECT OF REVOLUTION ON INFANT MORTALITY
*==========================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for treatment effects, and check treatment effect 
*   estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "e_peinfmor"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
* Marginsplot for visualizing trends
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Infant mortality") ylabel(100(10)150 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #55" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph47.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #48" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph48.pdf, replace
	* RESULT:  Lags are consistently negative (and relatively stable) but statistically insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Infant mortality") ylabel(45(5)65 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #49" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph49.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #50" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph50.pdf, replace
	* RESULT:  Lags are negative and statistically insignificant, but increase in effect over time.
	*	Implies the effect might become statistically significant over a longer period of time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatment effects in proximate years.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR2 and possibly AR1 processes that do not affect the statistical insignificance of treatment.


*===================================================
* EFFECT OF REVOLUTION ON UNDER-FIVE CHILD MORTALITY
*===================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for treatment effects, and check treatment effect 
*   estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "under5mort"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Under-5 child mortality") ylabel(180(10)270 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #51" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph51.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #52" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph52.pdf, replace
	* RESULT:  Lags are consistently negative (and relatively stable) but statistically insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR2 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
* Marginsplot for visualizing trends
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("Under-5 child mortality") ylabel(65(5)105 ,format(%9.0fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #53" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph53.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #54" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph54.pdf, replace
	* RESULT:  Lags are negative and statistically insignificant, but increase in effect over time.
	*	Implies the effect might become statistically significant over a longer period of time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence of alternative treatment effects in proximate years.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR2 and possibly AR1 processes that do not affect the statistical insignificance of treatment.


*====================================================================
* EFFECT OF REVOLUTION ON INCOME INEQUALITY (GINI INDEX)--FIGURE 9.10
*====================================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND GRAPH
*	PROVIDED IN FIGURE 9.10 IN BOOK
* 	INSUFFICIENT DATA AVAILABLE FOR MATCHED SAMPLES
*	NO ADDITIONAL ROBUSTNESS TESTS CARRIED OUT


*==========================================================
* EFFECT OF REVOLUTION ON STATE/PRIVATE PROPERTY OWNERSHIP
*==========================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Graphs of results produced here

* SUCCESSFUL SOCIAL VS. SUCCESSFUL URBAN CIVIC
use simplediffindifflong.dta, clear
global yvar = "vdstown_ord"
label var vdstown_ord "Private owndership of the economy (0-4)"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
global condvar = "leftist==1"
quietly: chp9simpmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.leftist##ib(2).year if success==1, fe vce(robust)
quietly: mimrgns, at(leftist=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM State/Property Index") ylabel(.5(.5)3.5 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Urban civic" 2 "Social" )) note("Graph #55" , span) title("`titvar1'" "Avg marginal predictions for successful episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph55.pdf, replace

* SUCCESSFUL URBAN CIVIC VS. FAILED URBAN CIVIC
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year if leftist==0, fe vce(robust)
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM State/Property Index") ylabel(1(.5)3 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed urban civic" 2 "Successful urban civic" )) note("Graph #56" , span) title("`titvar1'" "Avg marginal predictions for urban civic episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph56.pdf, replace

* SUCCESSFUL SOCIAL VS. FAILED SOCIAL
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year if leftist==1, fe vce(robust)
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM State/Property Index") ylabel(1(.5)3 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed social" 2 "Successful social" )) note("Graph #57" , span) title("`titvar1'" "Avg marginal predictions for urban civic episodes") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph57.pdf, replace

* URBAN CIVIC, EXCLUDING CASES OF POSTCOMMUNIST TRANSITIONS
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.success##ib(2).year if leftist==0 & incgovcommunist==0, fe vce(robust)
quietly: mimrgns, at(success=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM State/Property Index") ylabel(1.5(.5)3 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Failed urban civic" 2 "Successful urban civic" )) note("Graph #58" , span) title("`titvar1'" "Avg marginal predictions for urban civic (no post-comm)") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph58.pdf, replace


*==========================================
* EFFECT OF REVOLUTION ON GENDER INEQUALITY
*==========================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE
* Will provide graphs, test for treatment effects, and check treatment effect 
*   estimation assumptions


*=====================================
* WOMEN'S POLITICAL EMPOWERMENT INDEX
*=====================================

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "v2x_gender"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Political Empowerment Index") ylabel(.2(.1).5 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #59" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph59.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally significant evidence (at the .10 level) of violation of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #60" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph60.pdf, replace
	* RESULT:  Lags are consistently positive (and relatively stable) but statistically insignificant.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Political Empowerment Index") ylabel(.5(.05).7 , format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #61" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph61.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .05 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #62" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph62.pdf, replace
	* RESULT:  Lags are positive and mostly statistically significant, and relatively stable over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatment effects at t+1 and t+2 turn treatment effect statistically insignificant.
	*	Implies processes after revolution that influence the nature of the effect.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*=========================
* WOMEN'S CIVIL LIBERTIES
*=========================

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "v2x_gencl"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Civil Liberties Index") ylabel(.2(.1).5 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #63" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph63.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #64" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph64.pdf, replace
	* RESULT:  Lags are statistically insignificant but grow increasingly negative over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Civil Liberties Index") ylabel(.5(.05).7 , format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #65" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph65.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .01 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #66" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph66.pdf, replace
	* RESULT:  Lags are consistently positive and statistically significant, but deteriorate over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No alternative treatment effects that affect the statistical significance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and (possibly) AR2 processes that do not affect the statistical significance of treatment.


*========================================
* WOMEN'S PARTICIPATION IN CIVIL SOCIETY
*========================================

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "v2x_gencs"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
* Marginsplot for visualizing trends
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Part in Civil Society Index") ylabel(.2(.1).5 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #67" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph67.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #68" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph68.pdf, replace
	* RESULT:  Lags are statistically insignificant, positive, and relatively stable.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Part in Civil Society Index") ylabel(.5(.05).7 , format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #69" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph69.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .01 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #70" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph70.pdf, replace
	* RESULT:  Lags are consistently positive and statistically significant, and relatively stable over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Critical processes appear to take place at t+1 that turn treatment marginally significant. 
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*==================================
* WOMEN'S POLITICAL PARTICIPATION
*==================================

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "v2x_genpp"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if leftist==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Political Participation Index") ylabel(.2(.1).5 ,format(%9.1fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Successful social" )) note("Graph #71" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph71.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence of violation of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #72" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph72.pdf, replace
	* RESULT:  Lags are statistically insignificant, positive, and relatively stable.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No evidence that alternative treatments at work.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
quietly: mi estimate, post dots saving(miest, replace):  xtreg $yvar i.revny##ib(2).year if urbancivic==1 & success==1 [pweight=freqwt], fe cluster(revid)
quietly: mimrgns, at(revny=(0 1) year=(0 1 2 3 4 5 6 7 8 9 10)) predict(xb) noatlegend noestimcheck cmdmargins
* Marginsplot for visualizing trends
marginsplot, xdimension(year) noci xlabel(0 "t-3" 1 "t-2" 2 "t-1" 3 "Rev" 4 "t+1" 5 "t+2" 6 "t+3" 7 "t+4" 8 "t+5" 9 "t+6" 10 "t+7") ytitle("VDEM Women's Political Participation Index") ylabel(.5(.05).7 , format(%9.2fc) angle(0)) legend(pos(6) cols(2) order(1 "Matched" 2 "Succ urban civic" )) note("Graph #73" , span) title("`titvar1'" "Avg marginal predictions") plot1opts(msymbol(Oh) msize(medlarge)) plot2opts(msymbol(O) msize(medlarge))
graph export Robustnesstestfiles\Logfiles\robch9graph73.pdf, replace
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #74" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph74.pdf, replace
	* RESULT:  Lags are statistically insignificant and generally growing more positive over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatments at t+1 and t+2, but have no effect on the statistical insignificance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*===========================================
* EFFECT OF REVOLUTION ON POLITICAL KILLING
*===========================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.10
* Will test for treatment effects and check treatment effect estimation assumptions

* SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdclkill"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically significant evidence (at the .05 level) of violations of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally significant evidence (at the .10 level) that the effects were observed prior to treatment.
	*	Treatment likely related to levels of political killing.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #75" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph75.pdf, replace
	* RESULT:  Lags are statistically insignificant, positive, and relatively stable.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatments may be at work prior to revolution, but do not affect the statistical insignificance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .001 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #76" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph76.pdf, replace
	* RESULT:  Lags are positive, statistically significant, and relatively stable over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatments at t+1 is statistically significant, but does not affect the statistical significance of treatment.
	* 	Implies that some of the effect may occur in the first year after revolution as well.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*====================================================
* EFFECT OF REVOLUTION ON POLITICAL CIVIL LIBERTIES
*====================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.11
* Will test for treatment effects and check treatment effect estimation assumptions

* SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdpolitlib"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #77" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph77.pdf, replace
	* RESULT:  Lags are statistically insignificant, negative, and relatively stable.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No alternative treatments that affect the statistical insignificance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .001 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally statistically significant evidence (at the .10 level) for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #78" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph78.pdf, replace
	* RESULT:  Lags are positive, statistically significant, though slightly declining over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatment at t+1 is statistically significant and turns the statistical significance of treatment marginally significant (at the .10 level).
	* 	Implies that much of the effect is only evident in the first year after revolution.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*=================================================
* EFFECT OF REVOLUTION ON PRIVATE CIVIL LIBERTIES
*=================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.12
* Will test for treatment effects and check treatment effect estimation assumptions

// SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdclpriv"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #79" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph79.pdf, replace
	* RESULT:  Lags are statistically insignificant, negative, and grow increasingly negative over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No alternative treatments that affect the statistical insignificance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .001 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Statistically significant evidence (at the .05 level) for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally significant evidence (at the .10 level) that the effects were observed prior to treatment.
	*	Treatment likely related to private civil liberties.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #80" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph80.pdf, replace
	* RESULT:  Lags are positive, statistically significant, though declining over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatment at t-1 is statistically significant but does not alter the statistical significance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*=========================================
* EFFECT OF REVOLUTION ON THE RULE OF LAW
*=========================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.13
* Will test for treatment effects and check treatment effect estimation assumptions

* SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdrule"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #81" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph81.pdf, replace
	* RESULT:  Lags are statistically insignificant and hover around zero.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No alternative treatments that affect the statistical insignificance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .001 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally significant evidence (at the .10 level) that the effects were observed prior to treatment.
	*	Treatment likely related to rule of law.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #82" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph82.pdf, replace
	* RESULT:  Lags are positive, statistically significant, and slightly declining over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatment at t-1 is statistically significant but does not alter the statistical significance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.


*===================================================
* EFFECT OF REVOLUTION ON GOVERNMENT ACCOUNTABILITY
*===================================================
* REGRESSION RESULTS PRESENTED IN CHAPTER 9 DO-FILE, AND VISUAL RESULTS  
* 	PRESENTED IN FIGURE 9.14
* Will test for treatment effects and check treatment effect estimation assumptions

* SUCCESSFUL SOCIAL VS. MATCHED COUNTERPARTS
use matcheddiffindifflong.dta, clear
global yvar = "vdaccount"
global notetext "SUCCESSFUL SOCIAL VS. MATCHED CASES"
global condvar = "success==1 & leftist==1"
quietly{
local varlabel : var label $yvar
scalar titvar = "`varlabel'" 
scalar titvar = titvar +  ", " 
scalar titvar = titvar + "$yvar"
local titvar1 = titvar
}
quietly: chp9matchmultimp
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful social rev vs. no rev contention in matched counterparts
quietly: mi passive: generate treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Negative but statistically insignificant.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: Marginally statistically significant evidence (at the .10 level) of the parallel trends assumption
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #83" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph83.pdf, replace
	* RESULT:  Lags are statistically insignificant and hover around zero, though largely negative.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  No alternative treatments that affect the statistical insignificance of treatment.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 (and possibly AR2) processes that do not affect the statistical insignificance of treatment.


// SUCCESSFUL URBAN CIVIC VS. MATCHED COUNTERPARTS
global notetext "SUCCESSFUL URBAN CIVIC VS. MATCHED CASES"
global condvar = "success==1 & urbancivic==1"
//
// Testing for a statistically significant "treatment" effect
* Treatment consists of experiencing a successful urban civic rev vs. no rev contention in matched counterparts
quietly: mi passive: replace treat=0
quietly: mi passive: replace treat=1 if $condvar & year>2 & revny==1
mi estimate, cmdok post dots saving(miest, replace): xtdidregress ($yvar) (treat) if $condvar [pweight=freqwt], group(diffid) time(year) vce(cluster revid) 
	* RESULT:  Positive and statistically significant at the .001 level.
//
// TESTS FOR THE INTEGRITY OF THE TREATMENT EFFECT ESTIMATION
* I) Test for pre-treatment parallel trends (whether linear trends in the outcome variable  
* 	are parallel between control and treatment groups in the pretreatment period).
*    Statistical significance indicates that trends are not parallel.
quietly: chp9matchptrends
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence for violation of the parallel trends assumption.
//
* II) Granger test for whether treatment effects are observed in anticipation of actual treatment
*	Statistical significance indicates that effects are observed prior to treatment.
quietly: chp9matchgranger
quietly: mi query
quietly: local M = r(M)
di as txt "Averaged over " as res `M' as txt " imputations: F-score = " as res finalfscore as txt "   p-value = " as res finalpvalue
	* RESULT: No statistically significant evidence that the effects were observed prior to treatment.
//
* III) Grangerplot of lags and leads of the treatment time variable.
*	Used to assess whether there are any changes in the treatment effect over the post-treatment time period. 
* 	Visual evidence. Uses all available leads and lags, with effects normalized to first lead.quietly: chp9matchgrangerplot	
quietly: chp9matchgrangerplot
coefplot matrix(B[1]), ci((B[2] B[3])) vertical yline(0, lcolor(black) lwidth(thin) lpattern(dash)) caption({bf: $notetext }, size(medlarge) justification(center) alignment(bottom)) ciopts(recast(rcap)) note("Graph #84" , span) title("`titvar1'" "Effects over time (leads & lags w 95% CIs)", size(large)) ylabel(, angle(horizontal))
graph export Robustnesstestfiles\Logfiles\robch9graph84.pdf, replace
	* RESULT:  Lags are positive, statistically significant, and slightly declining over time.
//
* IV) Test for the influence of alternative treatments in surrounding periods
*	Examines whether there may be other "treatments" before or after revolution that affect the relationship
*	Uses these alternative periods as the treatment effect and then tests whether the actual treatment period remains statistically significant.
quietly: chp9matchalttreat
esttab , drop (*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("Rev" "Alt, t-2" "Alt, t-1" "Alt, t+1" "Alt, t+2") nonumbers title("Possible alternative treatment effects for " $yvar) coeflabels(r1vs0.treat "treat" r1vs0.alttreat "alttreat")
	* RESULT:  Alternative treatments at t-1 and t-2 are statistically significant but do not alter the statistical significance of treatment.
	*	Points to critical post-revolutionary processes in establishing government accountability.
//
* V) Lagged DV test
* 	Controls for possible effect of lagged values of the dependent variable on treatment the effect (up to 2 lags)
quietly: chp9matchdvlag
esttab , se drop(*.year _cons)  star (+ 0.10 * 0.05 ** 0.01 *** 0.001) nogaps  mtitles("No lag" "AR 1" "AR 2" "AR 1,2") nonumbers title("Testing for the possible effect of lagged values of the dependent variable for" $yvar) coeflabels(r1vs0.treat "treat")
	* RESULT: Evidence for AR1 and AR2 processes that do not affect the statistical significance of treatment.

 
log close

erase miest.ster

clear
